//
//  NotifyViewModel.swift
//  imprint
//
//  Created by 小柠檬🍋 on 2025/1/21.
//

import Foundation
import LeanCloud

class MyFeedbackViewModel : BaseViewModel {
    @Published var items = [MsgBean]()
    @Published var status = ""
    
    func getData(_ isRefresh: Bool = false) {
        requestList(isRefresh: isRefresh) {
            let query = LCQuery(className: "Msg")
            query.whereKey("userId", .equalTo(userManager.isLogin() ? userManager.getUserId() : getDeviceId()))
            query.limit = self.pageSize
            query.skip = self.pageNo * self.pageSize
            let list = try await LeancloudManager.instance.getList(query: query, modeType: MsgBean.self)
            try check(!isRefresh || !list.isEmpty, "暂无数据")
            return list
        } suc: {
            self.status = ""
            self.items.append(contentsOf: $0)
        } fail: {
            self.status = $0.message
        }
    }
}
